package com.touzhijia.authority.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.vote.AffirmativeBased;

import java.util.Collections;
import java.util.List;

/**
 * 作者：lizw <br/>
 * 创建时间：2017/11/16 11:03 <br/>
 */
@Configuration
@Slf4j
public class ApplicationSecurityBean {

//    @Autowired
//    private SecurityConfig securityConfig;
    @Autowired
    private CustomAccessDecisionVoter customAccessDecisionVoter;

    private AccessDecisionManager accessDecisionManager;
//    private SessionRegistry sessionRegistry;

    @Bean
    public AccessDecisionManager accessDecisionManager() {
        if (accessDecisionManager == null) {
            // WebExpressionVoter RoleVoter AuthenticatedVoter
            List<AccessDecisionVoter<?>> decisionVoters = Collections.singletonList(customAccessDecisionVoter);
            accessDecisionManager = new AffirmativeBased(decisionVoters);
        }
        return accessDecisionManager;
    }

//    @Bean
//    public SessionRegistry newSessionRegistry() {
//        if (sessionRegistry == null) {
//            sessionRegistry = new SessionRegistryImpl();
//        }
//        return sessionRegistry;
//    }
}